﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace AmazonDynamoDBStub.Extensions
{
    public static class CaseExtensions
    {
        private static T Cast<T>(dynamic o)
        { return (T)o; }

        /// <exception cref="System.InvalidCastException"></exception>
        public static dynamic DynamicCast(this Type type, dynamic o)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            return typeof(CaseExtensions).GetMethod("Cast", BindingFlags.Static | BindingFlags.NonPublic)
                .MakeGenericMethod(type).Invoke(null, new object[] { o });
        }
    }
}
